package com.example.takeaway.api;

import com.example.takeaway.common.R;
import com.example.takeaway.model.PageVO;
import com.example.takeaway.model.dto.DishDTO;
import com.example.takeaway.model.dto.DishEditorDTO;
import com.example.takeaway.model.dto.DishPageQuery;
import com.example.takeaway.model.vo.DishVO;
import com.example.takeaway.model.vo.SpecificationVO;
import com.example.takeaway.service.DishService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 * 菜品表 前端控制器
 * </p>
 *
 * @author 邢晨旭
 * @since 2023-10-12
 */
@RestController
@RequestMapping("/dish")
public class DishApi {

    @Resource
    DishService dishService;

    @PostMapping
    public R<Void> addDish(@RequestBody DishDTO param) {
        dishService.addDish(param);
        return R.ok();
    }

    @PutMapping
    public R<Void> updateDish(@RequestBody DishEditorDTO param) {
        dishService.updateDishById(param);
        return R.ok();
    }

    @DeleteMapping("/{id}")
    public R<Void> deleteDish(@PathVariable Long id) {
        dishService.deleteDishById(id);
        return R.ok();
    }

    @GetMapping("/{id}")
    public R<DishVO> getDishById(@PathVariable Long id) {
        return R.ok(dishService.getDishById(id));
    }

    @GetMapping("/page")
    public R<PageVO<DishVO>> get(DishPageQuery param) {
        return R.ok(dishService.queryPage(param));
    }

}
